package com.example.config;

import lombok.Data;
import org.apache.pulsar.client.api.SubscriptionType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Pulsar的配置信息
 *
 * @author yz
 */
@Data
@Component
@ConfigurationProperties(PulsarConfiguration.PREFIX)
public class PulsarConfiguration {
    public static final String PREFIX = "pulsar";

    /**
     * Pulsar的客户端
     */
    public List<PulsarConfig> clients = new ArrayList<>();

    @Data
    public static class PulsarConfig {
        /**
         * pulsar服务的唯一主键
         */
        private String id;
        /**
         * pulsar服务地址
         */
        private String serviceUrl;
        /**
         * 租户
         */
        private String tenant;
        /**
         * 命名空间
         */
        private String namespace;
        /**
         * 订阅的topic名称
         */
        private String topicNames;
        /**
         * 订阅者的名称
         */
        private String subscriptionName;
        /**
         * 操作超时，单位毫秒
         */
        private Integer operationTimeout;
        /**
         * IO线程数
         */
        private Integer ioThreads;
        /**
         * 消费者监听线程数
         */
        private Integer listenerThreads;
        /**
         * 是否开启TCP不延迟
         */
        private Boolean enableTcpNoDelay = true;

        private String retryLetterTopic = "retry-topic";
        private String deadLetterTopic = "dead-letter-topic";

        private int receiverQueueSize = 20;
        private int coreThreads = 5;
        private int maxCoreThreads = 10;
        private int keepAliveTime = 5;
        private int maxQueueLength = 100;
        private int maxRedeliverCount = 2;
        private long ackTimeout = 100000;
        private boolean persistent = true;
        private boolean enableRetry = false;
        private SubscriptionType subscriptionType = SubscriptionType.Exclusive;


        /**
         * 默认数据源名称：default
         */
        public static final String DEFAULT_SOURCE_NAME = "default";

        /**
         * 是否开启TCP不延迟
         */
        private Boolean defaultEnableTcpNoDelay = true;
        /**
         * 操作超时，单位秒
         */
        private Integer defaultOperationTimeout = 30;
        /**
         * 消费者监听线程数
         */
        private Integer defaultListenerThreads = 1;
        /**
         * IO线程数
         */
        private Integer defaultIoThreads = 1;
    }

}

